package com.strato.mvc.api.v1_0_0.view;

public class ViewName{
	private String resolver;
	private String path;
	private String bundle;
	
	public String getResolver() {
		return resolver;
	}
	public void setResolver(String resolver) {
		this.resolver = resolver;
	}
	public String getBundle() {
		return bundle;
	}
	public void setBundle(String bundle) {
		this.bundle = bundle;
	}
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public String toString(){
		StringBuffer buf=new StringBuffer();
		if(resolver!=null){
			buf.append(resolver).append(":");
		}
		if(path!=null){
			buf.append(path);
		}
		if(bundle!=null){
			buf.append("@").append(bundle);
		}
		return buf.toString();
	}

	public static ViewName parse(String viewName){
		ViewName vn=new ViewName();
		StringBuffer buf=new StringBuffer();
		for(int i=0,len=viewName.length();i<len;i++){
			char c=viewName.charAt(i);
			if(c==':'){
				vn.setResolver(buf.toString());
				buf.setLength(0);
			}else if(c=='@'){
				vn.setPath(buf.toString());
				buf.setLength(0);
			}else{
				buf.append(c);
			}
		}
		if(vn.getPath()==null){
			vn.setPath(buf.toString());
		}else{
			vn.setBundle(buf.toString());
		}
		return vn;
	}
}